﻿using CommonEngine;
using CommonFP;
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Threading.Tasks;

namespace CommonDevelop
{
    /// <summary>
    /// 业务层的基础操作
    /// </summary>
    public interface IBaseService<T> where T : class, new()
    {
        string IP();
        string BuildSeq();
        string BusinessKey();
        bool CleanUp();

        IEnumerable<T> GetList(string keyword = null, bool IsDelete = false);
        IEnumerable<T> GetPageList(Pagination Pag, string keyword = null, bool IsDelete = false);
        IEnumerable<TVO> GetList<TVO>(string keyword = null, bool IsDelete = false) where TVO : class, new();
        IEnumerable<TVO> GetPageList<TVO>(Pagination Pag, string keyword = null, bool IsDelete = false) where TVO : class, new();

        Task<T> GetEntity(object keyValue);
        Task<T> GetEntity(Expression<Func<T, bool>> expression, bool IsDelete);

        Validation<bool> Add_En(T En);
        Validation<bool> Add_En(IEnumerable<T> EnLs);
        Validation<bool> Save_En(T En);
        Validation<bool> Save_En(IEnumerable<T> EnLs);
        Validation<bool> VirtualDelete(object keyValue, string UserId, string UserName);
        Validation<bool> Delete(object keyValue);

        Option<TVO> Get<TVO>(object keyValue) where TVO : class, new();
        Option<TVO> GetMap<TVO>(T en) where TVO : class, new();
        IEnumerable<TVO> GetMapList<TVO>(IEnumerable<T> EnList) where TVO : class, new();
        IEnumerable<TVO> GetBind<TVO>(T en) where TVO : class, new();
        Validation<bool> Add<TVO>(TVO En) where TVO : class, new();
        Validation<bool> Save<TVO>(TVO En) where TVO : class, new();
    }
}
